package com.zcf.controller;

import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.zcf.common.json.Body;
import com.zcf.pojo.Dining;
import com.zcf.pojo.Freight;

import java.util.List;

import org.springframework.stereotype.Controller;

/**
 * <p>
 * 运送费 餐盒费 表 前端控制器
 * </p>
 *
 * @author loupeng
 * @since 2019-02-25
 */
@Controller
@RequestMapping("/freight")
@CrossOrigin
@ResponseBody
public class FreightController {

	/**
	 * 查询运送费
	 * 
	 * @return
	 */
	@PostMapping("addOneFreight")
	public Body addOneFreight() {
		Freight freigh = new Freight();
		freigh.setFreightId("15504681890651059481");
		freigh = freigh.selectById();
		if (freigh != null) {
			return Body.newInstance(freigh);
		}
		return Body.BODY_451;
	}

	/**
	 * 修改运送费
	 */
	@PostMapping("updateFreight")
	public Body updateFreight(Freight freight) {
		Boolean falg = freight.updateById();
		if (falg) {
			Dining dining=new Dining();
			List<Dining> list=dining.selectAll();
			for (Dining dining2 : list) {
				dining2.setFreight(freight.getMoneys());
				dining2.setBox(freight.getBoxMoney());
				Boolean fg=dining2.updateById();
			}
			return Body.BODY_200;
		}
		return Body.BODY_451;
	}

}
